//
//  MCMarcros.h
//  MCMarcros（宏定义指令）
//
//  Created by Apple on 15/4/24.
//  Copyright (c) 2015年 Apple. All rights reserved.
//

#import "AppDelegate.h"
#import "UIViewController+Message.h"

#define KDealloc(obj)if (obj) {obj = nil;};


//通知
#define NOTIF_ADD(n, f)          [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(f) name:n object:nil]
#define NOTIF_POSTInfo(n,o,info) [[NSNotificationCenter defaultCenter] postNotificationName:n object:o userInfo:info]
#define NOTIF_POST(n,o)          [[NSNotificationCenter defaultCenter] postNotificationName:n object:o]
#define NOTIF_REMV()             [[NSNotificationCenter defaultCenter] removeObserver:self]

//屏幕宽、高
#define kFullScreen          [UIScreen mainScreen].bounds
#define kScreenH             [[UIScreen mainScreen] bounds].size.height
#define kScreenW             [[UIScreen mainScreen] bounds].size.width

//不同屏幕尺寸字体适配（375，667是因为效果图为IPHONE6 如果不是则根据实际情况修改）//414 736
#define kScreenWidthRatio  (kScreenW / 375.0)
#define kScreenHeightRatio (kScreenH / 667.0)
//自动适配宽度、高度
#define kFitW(x)  ceilf((x) * kScreenWidthRatio)
#define kFitH(x)  ceilf((x) * kScreenHeightRatio)


/**************************
 * 项目总单例
 *************************/

#define ProjectAPP ((AppDelegate *)[[UIApplication sharedApplication] delegate])


/*************************
 大小设置
 *************************/

#ifndef kSysFont
#define kSysFont(s)              [UIFont systemFontOfSize:s]
#define kSysFontL(s)             [UIFont systemFontOfSize:s weight:UIFontWeightLight]
#define kSysFontR(s)             [UIFont systemFontOfSize:s weight:UIFontWeightRegular]
#define kSysFontB(s)             [UIFont systemFontOfSize:s weight:UIFontWeightBold]
#define kSysFontT(s)             [UIFont systemFontOfSize:s weight:UIFontWeightThin]
#endif



/*************************
 加载本地图片
 *************************/
#ifndef IMAGE
#define IMAGE(image) [UIImage imageNamed:image]
#endif

#ifndef PLACENIMAGE
#define PLACENIMAGE IMAGE(@"占位图")//占图片
#endif



/**************************
 * 在block中使用 《强弱引用》
 *************************/


#define WSELF(weakSelf) __weak typeof(self) weakSelf = self;
#define SSELF(strongSelf) __strong typeof(self) strongSelf = weakSelf;
#define kWeakSelf(type) __weak typeof(type) weak##type = type;
//#define kStrongSelf(type) __strong typeof(type) type = weak##type;






//解决arc时回调方法调用时的警告信息
//解决调用-(id)performSelector:(SEL)aSelector withObject:(id)object方法的警告
#define SuppressPerformSelectorLeakWarning(Stuff) \
do { \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \
Stuff; \
_Pragma("clang diagnostic pop") \
} while (0)



//整形转字符串
#define jIntToString(m) [NSString stringWithFormat:@"%d",m]
//整形转对象
#define jIntToNumber(m) [NSNumber numberWithInt:m]
//浮点型转字符串
#define jFloatToString(m) [NSString stringWithFormat:@"%.2f",m]



/**************************
 * 导航栏（iOS7）
 *************************/
#define NavBar_Height 64.0
//导航条高
#define NavHeight self.navigationController.navigationBar.height
//导航条全局
#define NAVGATIONBAR [UINavigationBar appearance]
//tabbar全局
#define TABBAR [UITabBar appearance]




//状态条高
//#define statusBarHeight [UIApplication sharedApplication].statusBarFrame.size.height


/**************************
 * 动画默认持续时间
 *************************/
#define AnimateDuration 0.25






/**************************
 * 黄金比例值
 *************************/
#define GP_VALUE 0.618


/************************
 * 获取颜色
 *************************/

#define RGBA(R,G,B,A) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:A]//通过指定RGB和透明度
#define hexCOLOR(hexColor) [UIColor colorWithHexString: hexColor]





/**************************
 * NSUserDefaults 实例化
 *************************/
#define UserDefault [NSUserDefaults standardUserDefaults]




/**************************
 * 检查系统版本，并与给定的某个值进行比较
 * SYSTEM_VERSION_EQUAL_TO                  等于
 * SYSTEM_VERSION_GREATER_THAN              大于
 * SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO  大于或等于
 * SYSTEM_VERSION_LESS_THAN                 小于
 * SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO     小于或等于
 *************************/
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)

#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)

#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

#define SystemVersion [[[UIDevice currentDevice] systemVersion] floatValue]//系统版本




/*************************
 条件提示框
 *************************/
#define CHECK(_condition_,_error_) if (_condition_) {\
[self showMessage:_error_];\
return;\
}\

#define CHECKWeakSelf(_condition_,_error_) if (_condition_) {\
[weakSelf showMessage:_error_];\
return;\
}\

#define CHECK_VC(_condition_,_error_,vc) if (_condition_) {\
[vc showMessage:_error_];\
return;\
}\


#define CHECKCENTER(_condition_,_error_) if (_condition_) {\
[self showMessage:_error_];\
return;\
}\

//可视化提示信息
//title和msg参数不能使用[NSString stringFormat:@"%x", xx]方法
#define MCAlertView(title, msg) \
UIAlertView *al = [[UIAlertView alloc] initWithTitle:(title) message:(msg) delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];[al show]




/**************************
 * GCD线程
 * BackgroundThreadPerformBlock  子线程运行block
 * MainThreadPerformBlock        主线程运行block
 * DelayMainThreadPerformBlock   主线程中延时secs秒后运行block
 *************************/
#ifndef BackgroundThreadPerformBlock
#define BackgroundThreadPerformBlock(block) dispatch_async(dispatch_queue_create(nil, DISPATCH_QUEUE_CONCURRENT), block)
#endif

#ifndef MainThreadPerformBlock
#define MainThreadPerformBlock(block) dispatch_async(dispatch_get_main_queue(),block)
#endif

#ifndef DelayMainThreadPerformBlock
#define DelayMainThreadPerformBlock(block,secs) dispatch_after(dispatch_time(DISPATCH_TIME_NOW, secs * NSEC_PER_SEC), dispatch_get_main_queue(), block)
#endif

//---------------------打印日志--------------------------
//Debug模式下打印方法名、所在行、内容
//#ifdef DEBUG
//#   define DBUGLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
//#else
//#   define DBUGLog(...)
//#endif


//---------------------打印日志--------------------------
//数组是否为空
//#define kArrayIsEmpty(array) (array == nil || [array isKindOfClass:[NSNull class]] || array.count == 0)
#ifndef IsSafeArray
#define IsSafeArray(a)              ((a)&&(![(a) isEqual:[NSNull null]]) &&((a).count>0))
#endif

//是否是空对象
#ifndef kObjectIsEmpty
#define kObjectIsEmpty(_object) (_object == nil \
|| [_object isKindOfClass:[NSNull class]] \
|| ([_object respondsToSelector:@selector(length)] && [(NSData *)_object length] == 0) \
|| ([_object respondsToSelector:@selector(count)] && [(NSArray *)_object count] == 0))
#endif

//字符串是否为空 返回Y N
#ifndef kStringIsEmpty
#define kStringIsEmpty(str) ([str isKindOfClass:[NSNull class]] || str == nil || [str length] < 1 ? YES : NO )
#endif
//字符串是否为空 返回空字符串 本身
#ifndef SafeString
#define SafeString(a)               ((((a)==nil)||([(a) isEqual:[NSNull null]])||((a).length==0))?@"":(a))
#endif

//字符串是否为空 运不运行
#ifndef IsSafeString
#define IsSafeString(a)             ((a)&& (![(a) isEqual:[NSNull null]]) &&((a).length>0))
#endif

//字典是否为空
#ifndef kDictIsEmpty
#define kDictIsEmpty(dic) (dic == nil || [dic isKindOfClass:[NSNull class]] || dic.allKeys == 0)
#endif


#define WarnIgnore_Deprecate(Stuff) \
do { \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") \
Stuff; \
_Pragma("clang diagnostic pop") \
} while (0)



//自定义错误提供给NSError使用
#define kCustomErrorDomain @"com.ETShop-for-iOS.ios"

